package preprocessing;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

import data.MatrixTime;

public class AreaNormalizer {
	
	public static void avg_area(List<MatrixTime> ets, PrintStream out) throws Exception {
		/*
		 * this function compute the mean of the given area for each hour.
		 * Thus, it also collect data in hourly form (original data are every 15 minutes)
		 */
		for(int m=0;m<ets.size();m = m+4) {
			List<MatrixTime> hourMatrix = new ArrayList<MatrixTime>();
			hourMatrix.add(ets.get(m));
			hourMatrix.add(ets.get(m+1));
			hourMatrix.add(ets.get(m+2));
			hourMatrix.add(ets.get(m+3));
			
			double mean = 0;
			double tot = 0;
			
			for(MatrixTime et: hourMatrix){
				double[][] mat = et.getMat();
				// compute spatial mean

				for(int i=0; i<mat.length;i++) 
					for(int j=0; j<mat[i].length;j++) {
						if(mat[i][j] >= 0) {
							mean += mat[i][j];
							tot ++;
						}
					}
			}
			
			mean = mean / tot;
			
			out.println(mean);
		}
	}

}
